using System;
using System.Data;
using System.Configuration;
using CodeWork.Library.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Data.SqlTypes;
using CodeWork.Library;
using System.Text;
using System.Data.SqlClient;

/// <summary>
/// ORM object that maps to tbl_userprofile
/// </summary>
namespace CodeWork.DAL.DataContainers.SqlServer
{
    public class Userprofile : SqlServerDAO
    {
        /// <summary>
        /// Self table parameters
        /// </summary>
        private int _id;
		private int _siteuserId;
		private string _firstName;
		private string _lastName;
		private DateTime _dateOfBirth;
		private string _country;
		private string _postalCode;
		private string _phoneNumber;

        /// <summary>
        /// Foriegn key parameters
        /// </summary>
        

        /// <summary>
        /// Self table properties
        /// </summary>
		public int Id
		{
			get { return this._id; }
			set { this._id = value; }
		}

		public int SiteuserId
		{
			get { return this._siteuserId; }
			set { this._siteuserId = value; }
		}

		public string FirstName
		{
			get { return this._firstName; }
			set { this._firstName = value; }
		}

		public string LastName
		{
			get { return this._lastName; }
			set { this._lastName = value; }
		}

		public DateTime DateOfBirth
		{
			get { return this._dateOfBirth; }
			set { this._dateOfBirth = value; }
		}

		public string Country
		{
			get { return this._country; }
			set { this._country = value; }
		}

		public string PostalCode
		{
			get { return this._postalCode; }
			set { this._postalCode = value; }
		}

		public string PhoneNumber
		{
			get { return this._phoneNumber; }
			set { this._phoneNumber = value; }
		}
		
        /// <summary>
        /// Foreign key properties, loaded on demand only
        /// </summary>
        

        /// <summary>
        /// Empty Constructor
        /// </summary>
        public Userprofile() { }

        /// <summary>
        /// Parameterized constructor
        /// </summary>
        /// <param name="id"></param>
		/// <param name="siteuserId"></param>
		/// <param name="firstName"></param>
		/// <param name="lastName"></param>
		/// <param name="dateOfBirth"></param>
		/// <param name="country"></param>
		/// <param name="postalCode"></param>
		/// <param name="phoneNumber"></param>
        public Userprofile
        (
            int id,
			int siteuserId,
			string firstName,
			string lastName,
			DateTime dateOfBirth,
			string country,
			string postalCode,
			string phoneNumber
        )
        {
            this._id = id;
			this._siteuserId = siteuserId;
			this._firstName = firstName;
			this._lastName = lastName;
			this._dateOfBirth = dateOfBirth;
			this._country = country;
			this._postalCode = postalCode;
			this._phoneNumber = phoneNumber;
        }

        /// <summary>
        /// Static save method. Saves the current instance in the table using the provided values using the
        /// primary key id. Expects that the Id is a primary key of an existing record in table.
        /// </summary>
        /// <param name="id"></param>
		/// <param name="siteuserId"></param>
		/// <param name="firstName"></param>
		/// <param name="lastName"></param>
		/// <param name="dateOfBirth"></param>
		/// <param name="country"></param>
		/// <param name="postalCode"></param>
		/// <param name="phoneNumber"></param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static bool Save
        (
            int id,
			int siteuserId,
			string firstName,
			string lastName,
			DateTime dateOfBirth,
			string country,
			string postalCode,
			string phoneNumber
        )
        {
            Userprofile userprofile = new Userprofile();
            userprofile.Id = id;
			userprofile.SiteuserId = siteuserId;
			userprofile.FirstName = firstName;
			userprofile.LastName = lastName;
			userprofile.DateOfBirth = dateOfBirth;
			userprofile.Country = country;
			userprofile.PostalCode = postalCode;
			userprofile.PhoneNumber = phoneNumber;

            return userprofile.Save();
        }

        /// <summary>
        /// Saves the current instance and returns result
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Save()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, Id);
			AddCommandParameter(command, "@SiteuserId", SqlDbType.Int, 0, ParameterDirection.Input, SiteuserId);
			AddCommandParameter(command, "@FirstName", SqlDbType.NVarChar, 50, ParameterDirection.Input, FirstName);
			AddCommandParameter(command, "@LastName", SqlDbType.NVarChar, 50, ParameterDirection.Input, LastName);
			AddCommandParameter(command, "@DateOfBirth", SqlDbType.DateTime, 0, ParameterDirection.Input, DateOfBirth);
			AddCommandParameter(command, "@Country", SqlDbType.NVarChar, 50, ParameterDirection.Input, Country);
			AddCommandParameter(command, "@PostalCode", SqlDbType.NVarChar, 50, ParameterDirection.Input, PostalCode);
			AddCommandParameter(command, "@PhoneNumber", SqlDbType.NVarChar, 50, ParameterDirection.Input, PhoneNumber);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_Save.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Saves the current instance based on provided conditions. This method assumes that
        /// conditions are provided in correct order and in proper format.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public bool Save(List<Condition> conditions)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            AddCommandParameter(command, "@NewSiteuserId", SqlDbType.Int, 0, ParameterDirection.Input, SiteuserId);
			AddCommandParameter(command, "@NewFirstName", SqlDbType.NVarChar, 50, ParameterDirection.Input, FirstName);
			AddCommandParameter(command, "@NewLastName", SqlDbType.NVarChar, 50, ParameterDirection.Input, LastName);
			AddCommandParameter(command, "@NewDateOfBirth", SqlDbType.DateTime, 0, ParameterDirection.Input, DateOfBirth);
			AddCommandParameter(command, "@NewCountry", SqlDbType.NVarChar, 50, ParameterDirection.Input, Country);
			AddCommandParameter(command, "@NewPostalCode", SqlDbType.NVarChar, 50, ParameterDirection.Input, PostalCode);
			AddCommandParameter(command, "@NewPhoneNumber", SqlDbType.NVarChar, 50, ParameterDirection.Input, PhoneNumber);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_SaveConditional.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Static creational method. This method actually adds a new entry in the table with
        /// the provided information.
        /// </summary>
        /// <param name="siteuserId"></param>
		/// <param name="firstName"></param>
		/// <param name="lastName"></param>
		/// <param name="dateOfBirth"></param>
		/// <param name="country"></param>
		/// <param name="postalCode"></param>
		/// <param name="phoneNumber"></param>
        /// <returns>Instance of the created object</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static Userprofile Create
        (
            int siteuserId,
			string firstName,
			string lastName,
			DateTime dateOfBirth,
			string country,
			string postalCode,
			string phoneNumber
        )
        {
            Userprofile userprofile = new Userprofile();
            userprofile.SiteuserId = siteuserId;
			userprofile.FirstName = firstName;
			userprofile.LastName = lastName;
			userprofile.DateOfBirth = dateOfBirth;
			userprofile.Country = country;
			userprofile.PostalCode = postalCode;
			userprofile.PhoneNumber = phoneNumber;

            return (userprofile.Create() ? userprofile : null);
        }

        /// <summary>
        /// Instance creational method. Inserts the current object as a new entry in table.
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Create()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@SiteuserId", SqlDbType.Int, 0, ParameterDirection.Input, SiteuserId);
			AddCommandParameter(command, "@FirstName", SqlDbType.NVarChar, 50, ParameterDirection.Input, FirstName);
			AddCommandParameter(command, "@LastName", SqlDbType.NVarChar, 50, ParameterDirection.Input, LastName);
			AddCommandParameter(command, "@DateOfBirth", SqlDbType.DateTime, 0, ParameterDirection.Input, DateOfBirth);
			AddCommandParameter(command, "@Country", SqlDbType.NVarChar, 50, ParameterDirection.Input, Country);
			AddCommandParameter(command, "@PostalCode", SqlDbType.NVarChar, 50, ParameterDirection.Input, PostalCode);
			AddCommandParameter(command, "@PhoneNumber", SqlDbType.NVarChar, 50, ParameterDirection.Input, PhoneNumber);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_Create.ToString());

            Id = (int)GetOneData(command);
            return (Id == 0 ? false : true);
        }

        /// <summary>
        /// Static deletion method. Deletes a record from table using the provided primary key id.
        /// </summary>
        /// <param name="id">Primary key</param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public static bool Delete(int id)
        {
            Userprofile userprofile = new Userprofile();
            userprofile.Id = id;

            return userprofile.Delete();
        }

        /// <summary>
        /// Static deletion method. Deletes a list record from table using the provided primary keys id.
        /// </summary>
        /// <param name="ids">List of primarky key id</param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public static bool Delete(List<int> ids)
        {
            string csvIds = Utility.MakeCSV(ids);

            Userprofile userprofile = new Userprofile();

            return userprofile.Delete(csvIds);
        }

        /// <summary>
        /// Static deletion method. Deletes records from table using provided conditions.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Boolean result as success or failure</returns>
        public static bool Delete(List<Condition> conditions)
        {
            Userprofile userprofile = new Userprofile();

            return userprofile.ConditionalDelete(conditions);
        }

        /// <summary>
        /// This is helper method for conditional delete method above. Not for other general use.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Boolean result as success or failure</returns>
        private bool ConditionalDelete(List<Condition> conditions)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_DeleteConditional.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// This is a helper method for multiple id delete method. Not for general use.
        /// </summary>
        /// <param name="csvIds">Comma seperated primary key values as string</param>
        /// <returns>Boolean result as success or failure</returns>
        private bool Delete(string csvIds)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Ids", SqlDbType.NVarChar, 500, ParameterDirection.Input, csvIds);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_DeleteMultiple.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Instance deletion method. Deletes the current instance from table.
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Delete()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, Id);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_DeleteOne.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Static selection method. Used for loading a perticular data using primary key id.
        /// </summary>
        /// <param name="id">Primary key</param>
        /// <returns>Instance of the loaded object</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static Userprofile Load(int id)
        {
            Userprofile userprofile = new Userprofile();
            userprofile.Id = id;

            if (userprofile.Load())
                return userprofile;
            else
                return null;
        }

        /// <summary>
        /// Instance selection method that fetches data using paging and sorting and also with 
        /// custom conditions.
        /// </summary>
        /// <param name="oderBy">Sorting order</param>
        /// <param name="startRow">Page start position</param>
        /// <param name="pageSize">Number of maximum record to be shown</param>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>List of instances of loaded objects</returns>
        public List<Userprofile> Load(string orderBy, int startRow, int pageSize, List<Condition> conditions)
        {
            List<Userprofile> userprofiles = new List<Userprofile>();
			
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@OrderBy", SqlDbType.NVarChar, 50, ParameterDirection.Input, orderBy);
            AddCommandParameter(command, "@StartRow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddCommandParameter(command, "@PageSize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_LoadConditionalPaged.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                Userprofile userprofile = (Userprofile)data;
                userprofiles.Add(userprofile);
            }

            return userprofiles;
        }

        /// <summary>
        /// Counts the number of total record available
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Count of the records</returns>
        public int LoadCount(List<Condition> conditions)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_LoadConditionalPagedCount.ToString());

            int returnValue = (int)GetOneData(command);
            return returnValue;
        }

        /// <summary>
        /// Instance selection method that fetches data using paging and sorting.
        /// </summary>
        /// <param name="oderBy">Sorting order</param>
        /// <param name="startRow">Page start position</param>
        /// <param name="pageSize">Number of maximum record to be shown</param>
        /// <returns>List of instances of loaded objects</returns>
        public List<Userprofile> Load(string orderBy, int startRow, int pageSize)
        {
            List<Userprofile> userprofiles = new List<Userprofile>();
            
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@OrderBy", SqlDbType.NVarChar, 50, ParameterDirection.Input, orderBy);
            AddCommandParameter(command, "@StartRow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddCommandParameter(command, "@PageSize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_LoadPaged.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                Userprofile userprofile = (Userprofile)data;
                userprofiles.Add(userprofile);
            }

            return userprofiles;
        }

        /// <summary>
        /// Counts the number of total record available
        /// </summary>
        /// <returns>Count of the records</returns>
        public int LoadCount()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_LoadPagedCount.ToString());

            int returnValue = (int)GetOneData(command);
            return returnValue;
        }

        /// <summary>
        /// Instance selection method. Used for reloading the current object from table. This method uses
        /// the Id of the current object to load and expects that the Id is correct.
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Load()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, Id);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_Load.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                Userprofile userprofile = (Userprofile)data;

                this._id = userprofile._id;
				this._siteuserId = userprofile._siteuserId;
				this._firstName = userprofile._firstName;
				this._lastName = userprofile._lastName;
				this._dateOfBirth = userprofile._dateOfBirth;
				this._country = userprofile._country;
				this._postalCode = userprofile._postalCode;
				this._phoneNumber = userprofile._phoneNumber;

                break;
            }

            return (dataList.Count > 0 ? true : false);
        }

        /// <summary>
        /// Instance selection method. Used for loading multiple record based on provided conditions.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>List of instances of loaded objects</returns>
        public List<Userprofile> Load(List<Condition> conditions)
        {
            List<Userprofile> userprofiles = new List<Userprofile>();

			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Userprofile_LoadConditional.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                Userprofile userprofile = (Userprofile)data;
                userprofiles.Add(userprofile);
            }

            return userprofiles;
        }

        /// <summary>
        /// Prepares the conditional parameters for use with Create/ Save/ Load/ Delete methods
        /// that use custom condition. Prepares the user Command object for using conditions.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        private void PrepareConditionalParameters(SqlCommand command, List<Condition> conditions)
        {
            StringBuilder condition = new StringBuilder();

            object id = null;
			object siteuserId = null;
			object firstName = null;
			object lastName = null;
			object dateOfBirth = null;
			object country = null;
			object postalCode = null;
			object phoneNumber = null;

            for (int i = 0; i < conditions.Count; i++)
            {
                string fieldName = Utility.ToHungarianNotation(conditions[i].FieldName);

                if (conditions[i].JoiningCondition == JoinOperator.FirstValue)
                {
                    condition.Append("WHERE ");
                }
                else if (conditions[i].JoiningCondition == JoinOperator.And)
                {
                    condition.Append(" AND ");
                }
                else if (conditions[i].JoiningCondition == JoinOperator.Or)
                {
                    condition.Append(" OR ");
                }

                condition.Append(conditions[i].FieldName).Append(" ").Append(Condition.MapCondition(conditions[i].ConditionalOperator)).Append("@" + fieldName);

                if ((conditions[i].ConditionalOperator == ConditionOperator.Like ||
                    conditions[i].ConditionalOperator == ConditionOperator.NotLike))
                {
                    if (string.IsNullOrEmpty(conditions[i].Value.ToString()))
                        conditions[i].Value = "%%%";
                    else
                        conditions[i].Value = "%" + conditions[i].Value.ToString() + "%";
                }

                if (fieldName == TableColumns.Id.ToString())
                    id = conditions[i].Value;
                else if (fieldName == TableColumns.SiteuserId.ToString())
					siteuserId = conditions[i].Value;
				else if (fieldName == TableColumns.FirstName.ToString())
					firstName = conditions[i].Value;
				else if (fieldName == TableColumns.LastName.ToString())
					lastName = conditions[i].Value;
				else if (fieldName == TableColumns.DateOfBirth.ToString())
					dateOfBirth = conditions[i].Value;
				else if (fieldName == TableColumns.Country.ToString())
					country = conditions[i].Value;
				else if (fieldName == TableColumns.PostalCode.ToString())
					postalCode = conditions[i].Value;
				else if (fieldName == TableColumns.PhoneNumber.ToString())
					phoneNumber = conditions[i].Value;
            }

            AddCommandParameter(command, "@Condition", SqlDbType.NVarChar, 2000, ParameterDirection.Input, condition.ToString());
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, id);
			AddCommandParameter(command, "@SiteuserId", SqlDbType.Int, 0, ParameterDirection.Input, siteuserId);
			AddCommandParameter(command, "@FirstName", SqlDbType.NVarChar, 50, ParameterDirection.Input, firstName);
			AddCommandParameter(command, "@LastName", SqlDbType.NVarChar, 50, ParameterDirection.Input, lastName);
			AddCommandParameter(command, "@DateOfBirth", SqlDbType.DateTime, 0, ParameterDirection.Input, dateOfBirth);
			AddCommandParameter(command, "@Country", SqlDbType.NVarChar, 50, ParameterDirection.Input, country);
			AddCommandParameter(command, "@PostalCode", SqlDbType.NVarChar, 50, ParameterDirection.Input, postalCode);
			AddCommandParameter(command, "@PhoneNumber", SqlDbType.NVarChar, 50, ParameterDirection.Input, phoneNumber);
        }

        /// <summary>
        /// Binds the fetched data from data reader to Objects
        /// </summary>
        /// <param name="reader">Data reader supplied by BaseDAO</param>
        /// <returns>List of object instances that was bound</returns>
        protected override List<BaseDAO> BindData(DbDataReader reader)
        {
            List<BaseDAO> result = new List<BaseDAO>();

			if (reader == null)
                return null;

            while (reader.Read())
            {
                Userprofile userprofile = new Userprofile
                (
					reader["id"] == System.DBNull.Value ? GetIdMinValue : (int)reader["id"],
                    reader["siteuser_id"] == System.DBNull.Value ? 0 : (int)reader["siteuser_id"],
					reader["first_name"] == System.DBNull.Value ? string.Empty : (string)reader["first_name"],
					reader["last_name"] == System.DBNull.Value ? string.Empty : (string)reader["last_name"],
					reader["date_of_birth"] == System.DBNull.Value ? SqlDateTime.MinValue.Value : (DateTime)reader["date_of_birth"],
					reader["country"] == System.DBNull.Value ? string.Empty : (string)reader["country"],
					reader["postal_code"] == System.DBNull.Value ? string.Empty : (string)reader["postal_code"],
					reader["phone_number"] == System.DBNull.Value ? string.Empty : (string)reader["phone_number"]
                );

                result.Add(userprofile);
            }
            
            if(!reader.IsClosed)
                reader.Close();

            return result;
        }

        /// <summary>
        /// List of store procedures that this class use
        /// </summary>
        private enum StoreProcedureName
        {
            Sp_Userprofile_Save = 0,
            Sp_Userprofile_Create = 1,
            Sp_Userprofile_DeleteOne = 2,
            Sp_Userprofile_DeleteMultiple = 3,
            Sp_Userprofile_DeleteConditional = 4,
            Sp_Userprofile_SaveConditional = 5,
            Sp_Userprofile_LoadConditional = 6,
            Sp_Userprofile_Load = 7,
            Sp_Userprofile_LoadConditionalPaged = 8,
            Sp_Userprofile_LoadConditionalPagedCount = 9,
            Sp_Userprofile_LoadPaged = 10,
            Sp_Userprofile_LoadPagedCount = 11
        }

        /// <summary>
        /// List of table column names that this class use
        /// </summary>
        private enum TableColumns
        {
            Id = 0,
			SiteuserId = 1,
			FirstName = 2,
			LastName = 3,
			DateOfBirth = 4,
			Country = 5,
			PostalCode = 6,
			PhoneNumber = 7
        }
    }
}